<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%--
  Created by IntelliJ IDEA.
  User: Wangliwei
  Date: 2017/6/18
  Time: 22:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>
<%if(session.getAttribute("uname")!=null)
{// 用户已登陆%>
<%! String DBDRIVER			= "com.mysql.jdbc.Driver" ;
  String DBURL			= "jdbc:mysql://127.0.0.1:3306/student" ;
  String DBUSER			= "root" ;
  String DBPASSWORD		= "" ;
  Connection conn			= null ;
  PreparedStatement pstmt	= null ; %>
<%// 接收参数
  int id = 0 ;
  try{id = Integer.parseInt(request.getParameter("num")) ;}
  catch(Exception e) {}%>
<%String sql = " delete from students where num = ? " ;
  boolean flag = false ;
  try{
    Class.forName(DBDRIVER) ;
    conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD) ;
    pstmt = conn.prepareStatement(sql) ;
    // 设置删除条件
    pstmt.setInt(1,id) ;
    pstmt.executeUpdate() ;
    pstmt.close() ;
    conn.close() ;
    flag = true ; }
  catch(Exception e) {}%>	<%response.setHeader("refresh","2;URL=list_notes.jsp") ;
  if(flag) {%>
信息删除成功，两秒后跳转到留言列表页！！！<br>
如果没有跳转，请按<a href="list_notes.jsp">这里</a>！！！
<%}else{%>
信息删除失败，两秒后跳转到留言列表页！！！<br>
如果没有跳转，请按<a href="list_notes.jsp">这里</a>！！！
<%}%>
<%}else{
  // 用户未登陆，提示用户登陆，并跳转
  response.setHeader("refresh","2;URL=Login.jsp") ;
%>您还未登陆，请先登陆！！！<br>
两秒后自动跳转到登陆窗口！！！<br>
如果没有跳转，请按<a href="login.jsp">这里</a>！！！<br>
<%}%>
<h3> <a href="main.jsp">回到功能列表页</a></h3>
</center>

</body>
</html>
